﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.IO;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

namespace SBS_Sprite_Sheeter
{
    public class SpriteElement
    {
        public Rectangle rect;
        public string name;

        public SpriteElement() { }
        public SpriteElement(Rectangle rect, string name)
        {
            this.rect = rect;
            this.name = name;
        }
    }

    public class SpriteSheet : IDisposable
    {
        #region Variables
        public Dictionary<string, SpriteElement> sprites = new Dictionary<string, SpriteElement>();
        public List<SpriteElement> spriteList = new List<SpriteElement>();
        public Texture2D texture;
        #endregion

        #region Constructor

        #endregion

        #region XNA Functions
        public static SpriteSheet Load(string str, string assetName, ContentManager Content)
        {
            return null;
        }

        public void Save(string str)
        {
            //StreamWriter writer = File.CreateText(str);
            StreamWriter writer = new StreamWriter(str);
            //Dictionary<string, SpriteElement>.Enumerator iter = sprites.GetEnumerator();
            //spriteList = new List<SpriteElement>();

            //while (iter.MoveNext())
            //{
            //    spriteList.Add(iter.Current.Value);
            //}

            foreach (SpriteElement element in sprites.Values)
            {
                writer.WriteLine(element.name.ToString());
                writer.WriteLine(element.rect.X.ToString() + " " + element.rect.Y.ToString() + " " + element.rect.Width.ToString() + " " + element.rect.Height.ToString());
            }
            writer.Close();
        }
        #endregion

        #region IDisposable Members
        public void Dispose()
        {
            if (texture != null)
            {
                texture.Dispose();
            }
            texture = null;
        }
        #endregion
    }
}